package com.sp.pay.repository.user;


import com.sp.pay.common.DateUtil;
import com.sp.pay.dto.QueryDto;
import com.sp.pay.dto.user.UserDto;
import com.sp.pay.mapper.user.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class UserRepositoryImp implements UserRepository{

    @Autowired
    private UserMapper userMapper;

    @Override
    public UserDto getByUserName(String user_name) {
        return userMapper.getByUserName(user_name);
    }

    @Override
    public List<UserDto> query(QueryDto queryDto) {
        return userMapper.query(queryDto);
    }

    public UserDto findById(int id){
        return userMapper.findById(id);
    }
    @Override
    public void save(UserDto userDto) {
        if(userDto.getId()>0){
            userMapper.update(userDto);
        }else {
            userDto.setAddTime(DateUtil.getCurrentDate("yyyy-MM-dd HH:mm:ss"));
            userMapper.insert(userDto);
        }
    }

    @Override
    public void delete(int id) {
        userMapper.delete(id);
    }
}
